<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath() %>'/>
<c-rt:set var="midHostname" value='<%=ServerValue.getMidHostname()%>'/>
<!-- 月历 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.datepick-zh-CN.js"></script>
<link rel="stylesheet" type="text/css" href="/css/smoothness.datepick.css" />
<!-- 数字验证 -->
<script type="text/javascript" charset="UTF-8" src="/js/jquery.alphanumeric.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/yaodian100.common.js"></script>
<script type="text/javascript" charset="UTF-8" src="/js/jquery.autotab-1.1b.js"></script>
<style type="text/css">
.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
<script language="javascript">
	$().ready( function() {
		$(":input[name*='ProdId']").each(function(){
			$("#" + this.id).numeric();
			$(this).blur(function(){
				$(this).val(prodPadLeft($(this).val()));
				getProductInfo("${midContextPath}",this.id + "_ProdName",$(this).val());
			});
		});

		$(":input[id*='adWord']").alphanumeric();
		$(":input[id*='adWord']").autotab_filter({ format: 'custom', pattern: '[^a-zA-Z0-9]' });
		
		$('#startDate').datepick({minDate: new Date(), showOn:'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"}); 
		$('#endDate').datepick({minDate: new Date(),showOn: 'both',numberOfMonths:2, buttonImageOnly: true, buttonImage: '/images/calendar.gif',dateFormat:"yy-mm-dd"});
		$("#subBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("10");
				$("#idxPromotionAdvForm").submit();
			}
		});

		$("#draftBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("00");
				$("#idxPromotionAdvForm").submit();
			}
		});
		
		$("#canBtn").click(function(){
			if ( validate_data() ){
				$("#advStatus").val("90");
				$("#idxPromotionAdvForm").submit();
			}
		});

		$("#tab1Img").change(function(){checkImg(document.idxPromotionAdvForm.tab1Img,30,245,265,$("#tab1ImgCorrect"),"") ;});
		$("#tab2Img").change(function(){checkImg(document.idxPromotionAdvForm.tab2Img,30,245,265,$("#tab2ImgCorrect"),"") ;});
		$("#tab3Img").change(function(){checkImg(document.idxPromotionAdvForm.tab3Img,30,245,265,$("#tab3ImgCorrect"),"") ;});
		$("#tab4Img").change(function(){checkImg(document.idxPromotionAdvForm.tab4Img,30,245,265,$("#tab4ImgCorrect"),"") ;});
	});

	function validate_data(){
		if ( $("#advName").val() == "" ){
			alert("请输入广告名称");
			$("#advName").focus();
			return false;
		}
		if ( $("#startDate").val() == ""){
			alert("请输入起始时间");
			$("#startDate").focus();
			return false;
		}

		if( $("#endDate").val() == "" ){
			alert("请输入结束时间");
			$("#endDate").focus();
			return false;
		}

		if($('#startDate').val()>$('#endDate').val()){
			alert('结束日期不能小于起始日期');
			$('#endDate').focus();
			return false;
		}else if($('#startDate').val()==$('#endDate').val()){
			if($('#startTime').val()>=$('#endTime').val()){
				alert('结束时间需大于起始时间');
				$('#endTime').focus();
				return false;
			}
		}
		
		for( var i = 1; i <= 4; i++ ){
			if ( $("#advId").val() == "" ){
				if ( $("#tab" + i + "Img").val() == "" ){
					alert("请输入Tab" + i + " 大图");
					$("#tab" + i + "Img").focus();
					return false;
				}
			}
			if ( $("#tab" + i + "ImgLink").val() == "" ){
				alert("请输入Tab" + i + " 图片点击连结");
				$("#tab" + i + "ImgLink").focus();
				return false;
			}
			if ( !isURL($("#tab" + i + "ImgLink").val()) ){
				alert("Tab" + i + " 图片点击连结格式错误");
				$("#tab" + i + "ImgLink").focus();
				return false;
			}
			if($("#tab" + i + "ImgCorrect").val()!=''){
				alert("Tab"+i+" "+$("#tab" + i + "ImgCorrect").val());
				$("#tab" + i + "Img").focus();
				return false;
			}	
			if($("#tab" + i + "ImgadWord").val()!="" && $("#tab" + i + "ImgadWord").val().match(/[^a-zA-Z0-9]/g)){
				alert("Tab" + i + "大图广告代码只能使用大小写英文字母、数字");
				return false;
			}
			
			if ( $("#tab" + i + "Title").val() == "" ){
				alert("请输入Tab" + i + " 标题文字");
				$(this).focus();
				return false;
			}
			for( var j = 1; j <=3; j++ ){
				if ( $("#tab" + i + "ProdId" + j).val() == ""){
					alert("请输入Tab" + i + " 商品编号" + j);
					$("#tab" + i + "ProdId" + j).focus();
					return false;
				}
				if('查无此商品' == $("#tab" + i + "ProdId" + j+"_ProdName").html()||
				   '此商品已被删除' == $("#tab" + i + "ProdId" + j+"_ProdName").html()||
				   '商品状态不正确' == $("#tab" + i + "ProdId" + j+"_ProdName").html()||
				   ($("#tab" + i + "ProdId" + j+"_ProdName").html().length>16 && $("#tab" + i + "ProdId" + j+"_ProdName").html().substring(0,16)=='赠品或加购商品无法被选为主打商品')){
					alert("Tab" + i + " 商品编号" + j+$("#tab" + i + "ProdId" + j+"_ProdName").html());
					$("#tab" + i + "ProdId" + j).focus();
					return false;
				}
				if($("#tab" + i + "Prod" + j +"adWord").val()!="" && $("#tab" + i + "Prod" + j +"adWord").val().match(/[^a-zA-Z0-9]/g)){
					$("#tab" + i + "Prod" + j +"adWord").focus();
					alert("Tab" + i +"商品编号"+j+"广告代码只能使用大小写英文字母、数字");
					return false;
				}
			}
		}	
		
		if ( $("#tab1Img").val() != "" )
			$("#tab1ImgName").val($("#tab1Img").val());

		if ( $("#tab2Img").val() != "" )
			$("#tab2ImgName").val($("#tab2Img").val());

		if ( $("#tab3Img").val() != "" )
			$("#tab3ImgName").val($("#tab3Img").val());

		if ( $("#tab4Img").val() != "" )
			$("#tab4ImgName").val($("#tab4Img").val());
		return true;
	}
</script>
<s:if test="hasErrors()">
<p><s:actionerror cssClass="msg rn" /></p>
</s:if>
<s:if test="hasActionMessages()">
<p><s:actionmessage cssClass="msg rn" /></p>
</s:if>
<s:if test="hasFieldErrors()">
<p><s:fielderror cssClass="msg rn" /></p>
</s:if>
<h1>广告管理</h1>
<s:form action="idxPromotion/saveIdxPromotionAdv_V2.do" method="post" name="idxPromotionAdvForm" id="idxPromotionAdvForm" enctype="multipart/form-data">
	<table class="tb-data" width="100%">
		<tbody>
			<tr>
				<th>类型</th>
				<td>首页類別促銷版位V3<input type="hidden" name="advType" id="advType" value="${advType}"/></td>
			</tr>
			<tr>
				<th>广告名称</th>
				<td><input type="text" id="advName" name="advName" value="${advName}" size="30" maxlength="30"/></td>
			</tr>
			<tr>
				<th>起迄时间</th>
				<td>
				<input type="text" id="startDate" name="startDate" value="${startDate}" maxlength="10"/>
				<select id="startTime" name="startTime">			
					<c-rt:forEach begin="0" end="23" var="t1">
						<c-rt:if test="${t1<10}">
						<c-rt:set value="0${t1}:00" var="sTime"></c-rt:set>
						</c-rt:if>
						<c-rt:if test="${t1>=10}">
						<c-rt:set value="${t1}:00" var="sTime"></c-rt:set>
						</c-rt:if>
						<option value="${sTime}" <c-rt:if test="${sTime==startTime}">selected</c-rt:if>>${sTime}</option>
					</c-rt:forEach>
				</select> ~ 
				<input type="text" id="endDate" name="endDate" value="${endDate}" maxlength="10"/>
				<select id="endTime" name="endTime">
					<c-rt:forEach begin="0" end="23" var="t2" >
						<c-rt:set var="t3">${23-t2}</c-rt:set>	
						<c-rt:if test="${t3<10}">
						<c-rt:set value="0${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<c-rt:if test="${t3>=10}">
						<c-rt:set value="${t3}:59" var="eTime"></c-rt:set>
						</c-rt:if>
						<option value="${eTime}" <c-rt:if test="${eTime==endTime }">selected</c-rt:if>>${eTime}</option>
					</c-rt:forEach>
				</select>				
				</td>
			</tr>
			<tr>
				<th>位置</th>
				<td>
					<select id="advTarget" name="advTarget">
						<option value="TOP"  ${advTarget eq "TOP" ? "selected" : ""}>上</option>
						<option value="MID" ${advTarget eq "MID" ? "selected" : ""}>中</option>
						<option value="BTM" ${advTarget eq "BTM" ? "selected" : ""}>下</option>
					</select>
				</td>
			</tr>
			<tr>
				<th colspan="4">tab设定</th>
			</tr>
			<tr>
				<th>Tab1</th>
				<td>
					<c-rt:if test="${not empty advId}">
						<img src="${midHostname }/eventImg/${tab1ImgFolder}/${advType}/${tab1ImgName}" width="75" height="75"/><br/>
					</c-rt:if>
					<b>大图:</b><s:file id="tab1Img" name="tab1Img" value="" size="60" ></s:file><br/><span>图片尺寸:245x265 &lt;30</span><br/>
					<b>图片点击连结:</b><input type="text" name="tab1ImgLink" id="tab1ImgLink" value="${tab1ImgLink}" size="60"/><br/><span>ex:http://www.yaodian100.com</span><br/>
					<b>大图广告代码:</b><input type="text" name="tab1ImgadWord" id="tab1ImgadWord" value="${tab1ImgadWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<input type="hidden" id="tab1ImgCorrect" value=""/>
					<input type="hidden" id="tab1ImgName" name="tab1ImgName" value="${tab1ImgName}"/>
					<input type="hidden" name="tab1ImgFolder" value="${tab1ImgFolder}"/>
					<b>Tab 标题文字:</b><input type="text" name="tab1Title" id="tab1Title" value="${tab1Title}" size="10" maxlength="5"/><span>字数限制:5个中文字</span><br/>
					<b>商品编号一:</b><input type="text" name="tab1ProdId1" id="tab1ProdId1" maxlength="8" size="10" value="${tab1ProdId1}"/>（请输入商品编号）<span id="tab1ProdId1_ProdName"></span><br/>
					<b>广告代码:</b><input type="text" name="tab1Prod1adWord" id="tab1Prod1adWord" value="${tab1Prod1adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<b>商品编号二:</b><input type="text" name="tab1ProdId2" id="tab1ProdId2" maxlength="8" size="10" value="${tab1ProdId2}"/>（请输入商品编号）<span id="tab1ProdId2_ProdName"></span><br/>
					<b>广告代码:</b><input type="text" name="tab1Prod2adWord" id="tab1Prod2adWord" value="${tab1Prod2adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<b>商品编号三:</b><input type="text" name="tab1ProdId3" id="tab1ProdId3" maxlength="8" size="10" value="${tab1ProdId3}"/>（请输入商品编号）<span id="tab1ProdId3_ProdName"></span><br/>
					<b>广告代码:</b><input type="text" name="tab1Prod3adWord" id="tab1Prod3adWord" value="${tab1Prod3adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
				</td>
			</tr>
			<tr>
				<th>Tab2</th>
				<td>
					<c-rt:if test="${not empty advId}">
						<img src="${midHostname }/eventImg/${tab2ImgFolder}/${advType}/${tab2ImgName}" width="75" height="75"/><br/>
					</c-rt:if>				
					<b>大图:</b><s:file id="tab2Img" name="tab2Img" value="" size="60" ></s:file><br/><span>图片尺寸:245x265 &lt;30</span><br/>
					<b>图片点击连结:</b><input type="text" name="tab2ImgLink" id="tab2ImgLink" value="${tab2ImgLink}" size="60"/><br/><span>ex:http://www.yaodian100.com</span><br/>
					<b>大图广告代码:</b><input type="text" name="tab2ImgadWord" id="tab2ImgadWord" value="${tab2ImgadWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<input type="hidden" id="tab2ImgCorrect" value=""/>
					<input type="hidden" id="tab2ImgName" name="tab2ImgName" value="${tab2ImgName}"/>	
					<input type="hidden" name="tab2ImgFolder" value="${tab2ImgFolder}"/>
					<b>Tab 标题文字:</b><input type="text" name="tab2Title" id="tab2Title" value="${tab2Title}" size="10" maxlength="5"/><span>字数限制:5个中文字</span><br/>
					<b>商品编号一:</b><input type="text" name="tab2ProdId1" id="tab2ProdId1" maxlength="8" size="10" value="${tab2ProdId1}"/>（请输入商品编号）<span id="tab2ProdId1_ProdName"></span><br/>
					<b>广告代码:</b><input type="text" name="tab2Prod1adWord" id="tab2Prod1adWord" value="${tab2Prod1adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<b>商品编号二:</b><input type="text" name="tab2ProdId2" id="tab2ProdId2" maxlength="8" size="10" value="${tab2ProdId2}"/>（请输入商品编号）<span id="tab2ProdId2_ProdName"></span><br/>
					<b>广告代码:</b><input type="text" name="tab2Prod2adWord" id="tab2Prod2adWord" value="${tab2Prod2adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<b>商品编号三:</b><input type="text" name="tab2ProdId3" id="tab2ProdId3" maxlength="8" size="10" value="${tab2ProdId3}"/>（请输入商品编号）<span id="tab2ProdId3_ProdName"></span><br/>
					<b>广告代码:</b><input type="text" name="tab2Prod3adWord" id="tab2Prod3adWord" value="${tab2Prod3adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
				</td>
			</tr>
			<tr>
				<th>Tab3</th>
				<td>
					<c-rt:if test="${not empty advId}">
						<img src="${midHostname }/eventImg/${tab3ImgFolder}/${advType}/${tab3ImgName}" width="75" height="75"/><br/>
					</c-rt:if>				
					<b>大图:</b><s:file id="tab3Img" name="tab3Img" value="" size="60" ></s:file><br/><span>图片尺寸:245x265 &lt;30</span><br/>
					<b>图片点击连结:</b><input type="text" name="tab3ImgLink" id="tab3ImgLink" value="${tab3ImgLink}" size="60"/><br/><span>ex:http://www.yaodian100.com</span><br/>
					<b>大图广告代码:</b><input type="text" name="tab3ImgadWord" id="tab3ImgadWord" value="${tab3ImgadWord}" size="20" maxlength="125"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<input type="hidden" id="tab3ImgCorrect" value=""/>
					<input type="hidden" id="tab3ImgName" name="tab3ImgName" value="${tab3ImgName}"/>
					<input type="hidden" name="tab3ImgFolder" value="${tab3ImgFolder}"/>
					<b>Tab 标题文字:</b><input type="text" name="tab3Title" id="tab3Title" value="${tab3Title}" size="10" maxlength="5"/><span>字数限制:5个中文字</span><br/>
					<b>商品编号一:</b><input type="text" name="tab3ProdId1" id="tab3ProdId1" maxlength="8" size="10" value="${tab3ProdId1}"/>（请输入商品编号）<span id="tab3ProdId1_ProdName"></span><br/>
					<b>广告代码:</b><input type="text" name="tab3Prod1adWord" id="tab3Prod1adWord" value="${tab3Prod1adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<b>商品编号二:</b><input type="text" name="tab3ProdId2" id="tab3ProdId2" maxlength="8" size="10" value="${tab3ProdId2}"/>（请输入商品编号）<span id="tab3ProdId2_ProdName"></span><br/>
					<b>广告代码:</b><input type="text" name="tab3Prod2adWord" id="tab3Prod2adWord" value="${tab3Prod2adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<b>商品编号三:</b><input type="text" name="tab3ProdId3" id="tab3ProdId3" maxlength="8" size="10" value="${tab3ProdId3}"/>（请输入商品编号）<span id="tab3ProdId3_ProdName"></span><br/>
					<b>广告代码:</b><input type="text" name="tab3Prod3adWord" id="tab3Prod3adWord" value="${tab3Prod3adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
				</td>
			</tr>	
			<tr>
				<th>Tab4</th>
				<td>
					<c-rt:if test="${not empty advId}">
						<img src="${midHostname }/eventImg/${tab4ImgFolder}/${advType}/${tab4ImgName}" width="75" height="75"/><br/>
					</c-rt:if>				
					<b>大图:</b><s:file id="tab4Img" name="tab4Img" value="" size="60" ></s:file><br/><span class="txt-rd">图片尺寸:245x265 &lt;30</span><br/>
					<b>图片点击连结:</b><input type="text" name="tab4ImgLink" id="tab4ImgLink" value="${tab4ImgLink}" size="60"/><br/><span >ex:http://www.yaodian100.com</span><br/>
					<b>大图广告代码:</b><input type="text" name="tab4ImgadWord" id="tab4ImgadWord" value="${tab4ImgadWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<input type="hidden" id="tab4ImgCorrect" value=""/>
					<input type="hidden" id="tab4ImgName" name="tab4ImgName" value="${tab4ImgName}"/>		
					<input type="hidden" name="tab4ImgFolder" value="${tab4ImgFolder}"/>
					<b>Tab 标题文字:</b><input type="text" name="tab4Title" id="tab4Title" value="${tab4Title}" size="10" maxlength="5"/><span>字数限制:5个中文字</span><br/>
					<b>商品编号一:</b><input type="text" name="tab4ProdId1" id="tab4ProdId1" maxlength="8" size="10" value="${tab4ProdId1}"/>（请输入商品编号）<span id="tab4ProdId1_ProdName"></span><br/>
					<b>广告代码:</b><input type="text" name="tab4Prod1adWord" id="tab4Prod1adWord" value="${tab4Prod1adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<b>商品编号二:</b><input type="text" name="tab4ProdId2" id="tab4ProdId2" maxlength="8" size="10" value="${tab4ProdId2}"/>（请输入商品编号）<span id="tab4ProdId2_ProdName"></span><br/>
					<b>广告代码:</b><input type="text" name="tab4Prod2adWord" id="tab4Prod2adWord" value="${tab4Prod2adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
					<b>商品编号三:</b><input type="text" name="tab4ProdId3" id="tab4ProdId3" maxlength="8" size="10" value="${tab4ProdId3}"/>（请输入商品编号）<span id="tab4ProdId3_ProdName"></span><br/>
					<b>广告代码:</b><input type="text" name="tab4Prod3adWord" id="tab4Prod3adWord" value="${tab4Prod3adWord}" size="20" maxlength="25"/><span>非必填。由英文字母、数字组成，最多25个半角</span><br/>
				</td>
			</tr>					
			<tr>
				<td colspan="2">
					<input type="hidden" id="advId" name="advId" value="${advId}"/>
					<input type="hidden" id="advStatus" name="advStatus" value="${advStatus}"/>
					<input type="button" id="subBtn" name="subBtn" value="发送"/>
					<input type="button" id="draftBtn" name="draftBtn" value="草稿"/>
					<input type="button" id="canBtn" name="canBtn" value="暂停"/>
				</td>
			</tr>												
		</tbody>
	</table>
</s:form>
<div class="f-link">
	<a href="${midContextPath}/generate/searchIdx.do">回广告查询页</a>
</div>